/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswedev.app.labhudson.view;

import javax.swing.JOptionPane;
import org.colswedev.app.labhudson.control.CustomerControl;
import org.colswedev.app.labhudson.control.TransactionControl;
import org.colswedev.app.labhudson.entity.Customer;

/**
 *
 * @author Leonardo Bohórquez
 */
public class pnlOptions extends javax.swing.JPanel {

    private Customer c;

    /**
     * Creates new form pnlOptions
     */
    public pnlOptions() {
	c = TransactionControl.getInstance().getCustomer();
	initComponents();
	lblWelcome.setText("Bienvenido, " + c.getName() + " " + c.getLastName());
	lblBalance.setText("Su saldo es: $" + c.getBalance().toString());
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT
     * modify this code. The content of this method is always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblWelcome = new javax.swing.JLabel();
        lblBalance = new javax.swing.JLabel();
        cmdWithdraw = new javax.swing.JButton();
        cmdConsign = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(500, 280));

        lblWelcome.setFont(new java.awt.Font("Tahoma", 0, 18));
        lblWelcome.setText("Bienvenido, ");

        lblBalance.setText("Su saldo es de ");

        cmdWithdraw.setText("Hacer un retiro");
        cmdWithdraw.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdWithdrawActionPerformed(evt);
            }
        });

        cmdConsign.setText("Hacer una consignación");
        cmdConsign.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdConsignActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblWelcome)
                            .addComponent(lblBalance)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(111, 111, 111)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmdWithdraw, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                            .addComponent(cmdConsign, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(244, 244, 244))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblWelcome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblBalance)
                .addGap(50, 50, 50)
                .addComponent(cmdWithdraw)
                .addGap(18, 18, 18)
                .addComponent(cmdConsign)
                .addContainerGap(113, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cmdWithdrawActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdWithdrawActionPerformed
	if (c.getBalance() != 0) {
	    FraMain.pnlMain.setVisible(false);
	    FraMain.pnlMain.removeAll();
	    FraMain.pnlMain.add(new pnlWithdraw());
	    FraMain.pnlMain.setVisible(true);
	} else {
	    JOptionPane.showMessageDialog(null, "Usted no tiene saldo disponiblo, por lo tanto, no puede hacer retiros");
	}
    }//GEN-LAST:event_cmdWithdrawActionPerformed

private void cmdConsignActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdConsignActionPerformed
    if (c.getBalance() != 0) {
	    FraMain.pnlMain.setVisible(false);
	    FraMain.pnlMain.removeAll();
	    FraMain.pnlMain.add(new pnlConsign());
	    FraMain.pnlMain.setVisible(true);
	} else {
	    JOptionPane.showMessageDialog(null, "Usted no tiene saldo disponiblo, por lo tanto, no puede hacer retiros");
	}
}//GEN-LAST:event_cmdConsignActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cmdConsign;
    private javax.swing.JButton cmdWithdraw;
    private javax.swing.JLabel lblBalance;
    private javax.swing.JLabel lblWelcome;
    // End of variables declaration//GEN-END:variables
}
